package org.example.y24.m9;

import java.util.Scanner;

public class Test1 {
    private static Integer size;// 棋盘大小
    private static Integer[][] arr;// 表示棋盘
    private static Integer count;// 填充计数器

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            size = (int) Math.pow(2, n);
            for (int i = 0; i < size; i++) {
                for (int j = 0; j < size; j++) {
                    arr = new Integer[size][size];
                    count = 0;
                    System.out.println("特殊格子坐标=(" + (i + 1) + "," + (j + 1) +")");
                    arr[i][j] = 0; 
                    Cover(0, 0, i, j, size);
                    Output(size);
                    System.out.println();
                }
            }
        }
    }
    public static void Cover(int leftRow, int leftCol, int specialRow, int specialCol, int size) {
        if (size < 2) {
            return;
        }

        count++;
        int flag = count;
        if (specialRow < leftRow + size / 2 && specialCol < leftCol + size / 2) {
            Cover(leftRow, leftCol, specialRow, specialCol, size / 2);

            arr[leftRow + size / 2 - 1][leftCol + size / 2] = flag;
            arr[leftRow + size / 2][leftCol + size / 2 - 1] = flag;
            arr[leftRow + size / 2][leftCol + size / 2] = flag;
            Cover(leftRow, leftCol + size / 2, leftRow + size / 2 - 1, leftCol + size / 2, size / 2); 
            Cover(leftRow + size / 2, leftCol, leftRow + size / 2, leftCol + size / 2 - 1, size / 2); 
            Cover(leftRow + size / 2, leftCol + size / 2, leftRow + size / 2, leftCol + size / 2, size / 2); 
        } else if (specialRow < leftRow + size / 2 && specialCol >= leftCol + size / 2) { 
            Cover(leftRow, leftCol + size / 2, specialRow, specialCol, size / 2);
            arr[leftRow + size / 2 - 1][leftCol + size / 2 - 1] = flag; 
            arr[leftRow + size / 2][leftCol + size / 2 - 1] = flag; 
            arr[leftRow + size / 2][leftCol + size / 2] = flag; 
            Cover(leftRow, leftCol, leftRow + size / 2 - 1, leftCol + size / 2 - 1, size / 2); 
            Cover(leftRow + size / 2, leftCol, leftRow + size / 2, leftCol + size / 2 - 1, size / 2); 
            Cover(leftRow + size / 2, leftCol + size / 2, leftRow + size / 2, leftCol + size / 2, size / 2); 
        } else if (specialRow >= leftRow + size / 2 && specialCol < leftCol + size / 2) { 
            Cover(leftRow + size / 2, leftCol, specialRow, specialCol, size / 2);
            arr[leftRow + size / 2 - 1][leftCol + size / 2 - 1] = flag; 
            arr[leftRow + size / 2 - 1][leftCol + size / 2] = flag; 
            arr[leftRow + size / 2][leftCol + size / 2] = flag;
            Cover(leftRow, leftCol, leftRow + size / 2 - 1, leftCol + size / 2 - 1, size / 2);
            Cover(leftRow, leftCol + size / 2, leftRow + size / 2 - 1, leftCol + size / 2, size / 2);
            Cover(leftRow + size / 2, leftCol + size / 2, leftRow + size / 2, leftCol + size / 2, size / 2);
        } else if (specialRow >= leftRow + size / 2 && specialCol >= leftCol + size / 2) { 
            Cover(leftRow + size / 2, leftCol + size / 2, specialRow, specialCol, size / 2);
            arr[leftRow + size / 2 - 1][leftCol + size / 2 - 1] = flag;
            arr[leftRow + size / 2 - 1][leftCol + size / 2] = flag;
            arr[leftRow + size / 2][leftCol + size / 2 - 1] = flag;
            Cover(leftRow, leftCol + size / 2, leftRow + size / 2 - 1, leftCol + size / 2, size / 2);
            Cover(leftRow + size / 2, leftCol, leftRow + size / 2, leftCol + size / 2 - 1, size / 2);
            Cover(leftRow, leftCol, leftRow + size / 2 - 1, leftCol + size / 2 - 1, size / 2);
        }
    }

    public static void Output(int size) {
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println("");
        }
    }
}